SG FileSys Overview

SG FileSys 1.0 |
Overview | © 1998 by Stinga
Reference Distribution License
Introduction

SG FileSys is FREE Automation compatible component that can be used to enumerate files and directories on Win32 file system. Main features include:

  • enumerate files and directories starting at specified root node
  • set file mask (i.e. *.dll)
  • set file attributes mask (i.e. enumerate compressed files)
  • exclude set of directories from the enumeration process
  • exclude set of files from the enumeration process
  • retrieve file's type description and icon
  • ideal extension for WSH scripts
  • SG FileSys is small, fast and does not need any external DLLs.
  • SG FileSys is FREE and can be downloaded from www.stinga.com.
Supported Platforms

SG FileSys is tested on Microsoft® Windows® 95, Windows® 98 and Windows® NT 4.0.

Contact Info

If you have any suggestions or ideas for new features and controls, or if you have any bugs to report please contact us. Your input is welcome at:

Stinga, Nova Cesta 151, 10000 Zagreb, Croatia
Web: http://www.stinga.com/sgfilesys
E-mail: sgfilesys@stinga.com


Distribution Notes

SG FileSys |
Distribution Notes | ©1998 by Stinga
Overview Reference
Distributable Files

SG FileSys does not need any runtime DLLs. All you need to distribute is SGFILESYS.DLL file.

To distribute applications and scripts that use SG FileSys you must include SGFILESYS.DLL into your setup program and register it on a client machine. SGFILESYS.DLL contains version info and you should ensure that setup program is not overwriting a newer version of SG FileSys. SGFILESYS.DLL is self registering module and you can register it with

REGSVR32.EXE /S SGFILESYS.DLL

command or you can let VB Setup Wizard create installation program for your VB projects.

Supported Platforms

SG FileSys is tested on Microsoft® Windows® 95, Windows® 98 and Windows® NT 4.0.


License

SG FileSys |
License Agreement | ©1998 by Stinga
Overview Examples

SG FileSys is FREE and you can use it in any project: commercial or public domain.

You can visit as at www.stinga.com.
If you have any comment or suggestion feel free to email us at sgfilesys@stinga.com.


SG FileSys Examples

SG FileSys |
Examples | ©1998 by Stinga
Overview Constants Error Codes

This sample lists all VBScript files on the C: drive. Look at VBScript or JScript code.

VBScript Sample
 Option Explicit

 ' Attribute constants
 const sgfAll          = &H00001FF7&
 const sgfArchive      = &H00000020&
 const sgfCompressed   = &H00000800&
 const sgfDirectory    = &H00000010&
 const sgfEncrypted    = &H00000040&
 const sgfHidden       = &H00000002&
 const sgfNormal       = &H00000080&
 const sgfOffline      = &H00001000&
 const sgfReadOnly     = &H00000001&
 const sgfReparsePoint = &H00000400&
 const sgfSparseFile   = &H00000200&
 const sgfSystem       = &H00000004&
 const sgfTemporary    = &H00000100&

 Dim en, item
 Set en = CreateObject("SGFileSys.Enumerator")

 en.RootPath = "C:\"
 en.Recurse = True
 en.NameMask = "*.vbs"
 en.AttributeMask = sgfAll - sgfDirectory

 For Each item In en.Items
    WScript.Echo item.Path
 Next
JScript Sample
 var sgfAll = 0x00001FF7;
 var sgfArchive = 0x00000020;
 var sgfCompressed = 0x00000800;
 var sgfDirectory = 0x00000010;
 var sgfEncrypted = 0x00000040;
 var sgfHidden = 0x00000002;
 var sgfNormal = 0x00000080;
 var sgfOffline = 0x00001000;
 var sgfReadOnly = 0x00000001;
 var sgfReparsePoint = 0x00000400;
 var sgfSparseFile = 0x00000200;
 var sgfSystem = 0x00000004;
 var sgfTemporary = 0x00000100;

 var en = new ActiveXObject("SGFileSys.Enumerator")

 en.RootPath = "C:\\"
 en.Recurse = true;
 en.NameMask = "*.vbs";
 en.AttributeMask &= ~sgfDirectory;

 // Create JScript enumerator
 // Do this after enumeration properties have been set
 var items = new Enumerator(en.Items);

 for (; !items.atEnd(); items.moveNext())
 {
    var item = items.item();
    WScript.Echo(item.Path);
 }


SG FileSys Reference

SG FileSys |
Reference | ©1998 by Stinga


Enumerator Object

SG FileSys |
Enumerator Object | ©1998 by Stinga
Overview Properties Methods Constants Error Codes
ProgID | SGFileSys.Window
CLSID | F6D331E6-3AAD-11D2-9889-204C4F4F5020

Description

Enumerator object is responsible for setting enumeration parameters. By setting it's properties, you can control which files and/or folders are enumerated. Folowing is a list of parameters that can be changed:

  • enumeration root path
  • enumerated files mask
  • enumerated files attribute mask
  • folders excluded from enumeration process
  • file extensions excluded from enumeration process
  • recurse flag.

Example

Folowing example is WSH script that scans C: drive and prints all VBScript files:

 Option Explicit
 Dim en, item
 Set en = CreateObject("SGFileSys.Enumerator")

 en.RootPath = "C:/"
 en.Recurse = True
 en.NameMask = "*.vbs"

 For Each item In en.Items
    WScript.Echo item.Path
 Next


Enumerator Properties

SG FileSys |
Enumerator Properties | ©1998 by Stinga
Enumerator Object Constants Error Codes

RootPath | Returns or sets root path for this enumerator.
NameMask | Returns or sets file name mask.
AttributeMask | Enumerator matches items that have any attribute specified in the AttributeMask property.
Recurse | Returns or sets recurse flag.
ExcludedFolders | Returns or sets folders that are not enumerated.
ExcludedExt | Returns or sets file extensions that are not enumerated.
Items | Returns collection of file system items. Read only.


AttributeMask Property

SG FileSys |
AttributeMask Property | ©1998 by Stinga
Enumerator Object Constants Error Codes
Description

Returns or sets attributes mask.

Syntax

object.AttributeMask As Long

The object is expression that evaluates to the Enumerator object.

Remarks

Enumerator matches items that have any attribute specified in the AttributeMask property. AttributeMask can be any combination of the following flags:

sgfAll | All flags
sgfReadOnly | The file or directory is read-only. Applications can read the file but cannot write to it or delete it. In the case of a directory applications cannot delete it.
sgfHidden | The file or directory is hidden. It is not included in an ordinary directory listing
sgfSystem | The file or directory is part of the operating system or is used exclusively by the operating system
sgfDirectory | The item identifies a directory
sgfArchive | The file or directory is an archive file or directory. Applications use this attribute to mark files for backup or removal
sgfEncrypted | The file or directory is encrypted. For a file this means that all data streams are encrypted. For a directory this means that encryption is the default for newly created files and subdirectories
sgfNormal | The file or directory has no other attributes set. This attribute is valid only if used alone
sgfTemporary | The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access rather than flushing it back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed
sgfSparseFile | The file is a sparse file
sgfReparsePoint | The file has an associated reparse point
sgfCompressed | The file or directory is compressed. For a file this means that all of the data in the file is compressed. For a directory this means that compression is the default for newly created files and subdirectories
sgfOffline | The file data is not immediately available. Indicates that the file data has been physically moved to offline storage
Example

Following example lists all hidden files in the C:\windows directory:

 Option Explicit
 Dim en, item
 Set en = CreateObject("SGFileSys.Enumerator")

 en.RootPath = "C:/windows/"
 en.Recurse = True
 en.NameMask = "*.*"
 en.AttributeMask = sgfHidden

 For Each item In en.Items
    WScript.Echo item.Path
 Next


ExcludedExt Property

SG FileSys |
ExcludedExt Property | ©1998 by Stinga
Enumerator Object Constants Error Codes
Description

Returns or sets string that contains list of file extensions that are not enumerated.

Syntax

object.ExcludedExt As String

The object is expression that evaluates to the Enumerator object.

Remarks

Extensions must be separated with semicolon (:) character.

Example

Following example lists files from the C:/Projects and it's subdirectories. Files and directories with extensions 'obj', 'pch' and 'pdb' are not listed.

 Option Explicit
 Dim en, item
 Set en = CreateObject("SGFileSys.Enumerator")

 en.RootPath = "C:/Projects/"
 en.Recurse = True
 en.NameMask = "*.*"
 en.ExcludedExt = "obj:pch:pdb"

 For Each item In en.Items
    WScript.Echo item.Path
 Next


ExcludedFolders

SG FileSys |
ExcludedFolders Property | ©1998 by Stinga
Enumerator Object Constants Error Codes
Description

Returns or sets string that contains list of directories that are not enumerated or recursed.

Syntax

object.ExcludedFolders As String

The object is expression that evaluates to the Enumerator object.

Remarks

Directory names must be separated with semicolon (:) character.

Example

Following example lists files from the C:/Projects and it's subdirectories. Files in directories named 'Debug' and 'Release' are not listed.

 Option Explicit
 Dim en, item
 Set en = CreateObject("SGFileSys.Enumerator")

 en.RootPath = "C:/Projects/"
 en.Recurse = True
 en.NameMask = "*.*"
 en.ExcludedFolders = "Debug:Release"

 For Each item In en.Items
    WScript.Echo item.Path
 Next


NameMask Property

SG FileSys |
NameMask Property | ©1998 by Stinga
Enumerator Object Constants Error Codes
Description

Returns or sets file name mask.

Syntax

object.NameMask As String

The object is expression that evaluates to the Enumerator object.

Remarks

During enumeration process, file and folder names are matched against the name mask. If name is matched, that file or folder is accepted and emitted as next valid item. Inside name mask string, you can use wildcard characters:

* - matches 0 or more characters in file name text
? - matches exactly one character in file name text

Example

Following example prints all directories with name that starts with letter 's' and ends with letter 'p':

 Option Explicit
 Dim en, item
 Set en = CreateObject("SGFileSys.Enumerator")

 en.RootPath = "C:/"
 en.Recurse = True
 en.NameMask = "s*p.*"
 en.AttributeMask = sgfDirectory

 For Each item In en.Items
    WScript.Echo item.Path
 Next


Items Property

SG FileSys |
Items Property | ©1998 by Stinga
Enumerator Object Constants Error Codes
Description

Collection of file system items.

Syntax

object.Items As Object

The object is expression that evaluates to the Enumerator object.

Remarks

Use this property within For...Each construct.

Example
 Option Explicit
 Dim en, item
 Set en = CreateObject("SGFileSys.Enumerator")

 en.RootPath = "C:/"
 en.NameMask = "*.*"

 For Each item In en.Items
    WScript.Echo item.Path
 Next


Recurse Property

SG FileSys |
Recurse Property | ©1998 by Stinga
Enumerator Object Constants Error Codes
Description

Returns or sets recurse flag. If this flag is True, SG FileSys will recurse directories under the root path specified in the RootPath property.

Syntax

object.Recurse As Boolean

The object is expression that evaluates to the Enumerator object.


RootPath Property

SG FileSys |
RootPath Property | ©1998 by Stinga
Enumerator Object Constants Error Codes
Description

Returns or sets enumeration root path.

Syntax

object.RootPath As String

The object is expression that evaluates to the Enumerator object.

Remarks

Path must be ended with trailing slash/backslash character.

Example
 Set en = CreateObject("SGFileSys.Enumerator")
 en.RootPath = "C:/Windows/"


Enumerator Methods

SG FileSys |
Enumerator Methods | ©1998 by Stinga
See Also Overview Constants Error Codes

Enumerator object does not have any methods.


Item Object

SG FileSys |
Item Object | ©1998 by Stinga
Overview Properties Constants Error Codes
ProgID | Not creatable
CLSID | F6D331E8-3AAD-11D2-9889-204C4F4F5020
Description

Item object represents single file or directory. The only way to retrieve Item object is to enumerate Items collection in For...Each loop.


Item Object Properties

SG FileSys |
Item Object Properties | ©1998 by Stinga
Overview Constants Error Codes

Attributes | File attributes. Read only.
CompressedFileSize | Low-order value of the the actual number of bytes of disk storage used to store a file. Read only.
CompressedFileSizeHigh | High-order value of the the actual number of bytes of disk storage used to store a file. Read only.
DateCreated | Time the file was created. Read only.
DateLastAccessed | Time the file was last accessed. Read only.
DateLastModified | Time the file was last written to. Read only.
Dir | Directory path including trailing slash. Read only.
Drive | Drive letter followed by a colon (:). Read only.
Ext | File name extension. Read only.
FileSize | Low-order value of the file size in bytes. Read only.
FileSizeHigh | High-order value of the file size in bytes. Read only.
Icon | Icon that represents the file. Read only.
Name | Item's name. Read only.
Path | Full path with file name and extension. Read only.
ShortName | File name in the classic 8.3 (filename.ext) filename format. Read only.
TypeName | String that describes the file's type. Read only.


Attributes Property

SG FileSys |
Attributes Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns the file attributes. For a list of valid values look at the remarks section.

Syntax

object.Attributes As Long

The object is expression that evaluates to the Item object.

Remarks

Attributes property can be any combination of the folowing flags:

sgfAll | All flags
sgfReadOnly | The file or directory is read-only. Applications can read the file but cannot write to it or delete it. In the case of a directory applications cannot delete it.
sgfHidden | The file or directory is hidden. It is not included in an ordinary directory listing
sgfSystem | The file or directory is part of the operating system or is used exclusively by the operating system
sgfDirectory | The item identifies a directory
sgfArchive | The file or directory is an archive file or directory. Applications use this attribute to mark files for backup or removal
sgfEncrypted | The file or directory is encrypted. For a file this means that all data streams are encrypted. For a directory this means that encryption is the default for newly created files and subdirectories
sgfNormal | The file or directory has no other attributes set. This attribute is valid only if used alone
sgfTemporary | The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access rather than flushing it back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed
sgfSparseFile | The file is a sparse file
sgfReparsePoint | The file has an associated reparse point
sgfCompressed | The file or directory is compressed. For a file this means that all of the data in the file is compressed. For a directory this means that compression is the default for newly created files and subdirectories
sgfOffline | The file data is not immediately available. Indicates that the file data has been physically moved to offline storage


CompressedFileSize Property

SG FileSys |
CompressedFileSize Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns low-order value of the the actual number of bytes of disk storage used to store a file. Read only.

Syntax

object.CompressedFilesize As Long

The object is expression that evaluates to the Item object.


CompressedFileSizeHigh Property

SG FileSys |
CompressedFileSizeHigh Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns high-order value of the the actual number of bytes of disk storage used to store a file. Read only.

Syntax

object.CompressedFilesizeHigh As Long

The object is expression that evaluates to the Item object.


DateCreated Property

SG FileSys |
DateCreated Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns time the file was created. Read only.

Syntax

object.DateCreated As Date

The object is expression that evaluates to the Item object.


DateLastAccessed Property

SG FileSys |
DateLastAccessed Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns time the file was last accessed. Read only.

Syntax

object.DateLastAccessed As Date

The object is expression that evaluates to the Item object.


DateLastModified Property

SG FileSys |
DateLastModified Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns time the file was last written to. Read only.

Syntax

object.DateLastModified As Date

The object is expression that evaluates to the Item object.


Dir Property

SG FileSys |
Dir Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns directory path including trailing slash. Read only.

Syntax

object.Dir As String

The object is expression that evaluates to the Item object.


Drive Property

SG FileSys |
Drive Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns drive letter followed by a colon (:). Read only.

Syntax

object.Drive As String

The object is expression that evaluates to the Item object.


Ext Property

SG FileSys |
Ext Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns file name extension. Read only.

Syntax

object.Ext As String

The object is expression that evaluates to the Item object.


FileSize Property

SG FileSys |
FileSize Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns low-order value of the file size in bytes. Read only.

Syntax

object.FileSize As Long

The object is expression that evaluates to the Item object.


FileSizeHigh Property

SG FileSys |
FileSizeHigh Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns high-order value of the file size in bytes. Read only.

Syntax

object.FileSizeHigh As Long

The object is expression that evaluates to the Item object.


Icon Property

SG FileSys |
Icon Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns icon that represents the file. Read only.

Syntax

object.Icon(size as IconSize) As Object

Part | Description
object | The object is expression that evaluates to the Item object.
size | Required. Size of the icon to retrieve or set. Value for the size parameter can be obtained from the IconSize enumeration.
Remarks

Size can be one of this values:

Small_16x16 | &H00000010& | 16
Big_32x32 | &H00000020& | 32


Name Property

SG FileSys |
Name Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns file or folder name with optional extension. Read only.

Syntax

object.Name As String

The object is expression that evaluates to the Item object.


Path Property

SG FileSys |
Path Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns full path with file name and extension. For directories, path is terminated with trailing slash. Read only.

Syntax

object.Path As String

The object is expression that evaluates to the Item object.


ShortName Property

SG FileSys |
ShortName Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns file name in the classic 8.3 (filename.ext) filename format. Read only.

Syntax

object.ShortName As Short

The object is expression that evaluates to the Item object.


TypeName Property

SG FileSys |
TypeName Property | ©1998 by Stinga
Overview Constants Error Codes
Description

Returns string that describes the file's type. Read only.

Syntax

object.TypeName As String

The object is expression that evaluates to the Item object.


Item Object Methods

SG FileSys |
Item Object Methods | ©1998 by Stinga
Overview Constants Error Codes

Item object does not have any methods.


Items Collection

SG FileSys |
Items Collection | ©1998 by Stinga
Overview Constants Error Codes
ProgID | Not creatable
CLSID | AC1ECC63-3AA9-11D2-9889-204C4F4F5020
Description

Items object is a collection of enumerated items. It has no properties or methods - the only way to use it is inside the For ... Each loop.

Example

Folowing example lists all files whose extension begins with character 'B':

Option Explicit

Dim en, item, items
Set en = CreateObject("SGFileSys.Enumerator")
en.RootPath = "C:\"
en.fileMask = "*.b??"
en.Recurse = False

Set items = en.Items
For Each item In items
   MsgBox item.Path
Next


SG FileSys Constants

SG FileSys |
Constants | ©1998 by Stinga
Overview Error Codes
  • Attributes
  • IconSize
Constant | Description | Hex Value | Decimal Value
sgfAll | All flags | 0xFFFFFFFF | -1
sgfReadOnly | The file or directory is read-only. Applications can read the file but cannot write to it or delete it. In the case of a directory applications cannot delete it. | 0x00000001 | 1
sgfHidden | The file or directory is hidden. It is not included in an ordinary directory listing | 0x00000002 | 2
sgfSystem | The file or directory is part of the operating system or is used exclusively by the operating system | 0x00000004 | 4
sgfDirectory | The item identifies a directory | 0x00000010 | 16
sgfArchive | The file or directory is an archive file or directory. Applications use this attribute to mark files for backup or removal | 0x00000020 | 32
sgfEncrypted | The file or directory is encrypted. For a file this means that all data streams are encrypted. For a directory this means that encryption is the default for newly created files and subdirectories | 0x00000040 | 64
sgfNormal | The file or directory has no other attributes set. This attribute is valid only if used alone | 0x00000080 | 128
sgfTemporary | The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access rather than flushing it back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed | 0x00000100 | 256
sgfSparseFile | The file is a sparse file | 0x00000200 | 512
sgfReparsePoint | The file has an associated reparse point | 0x00000400 | 1024
sgfCompressed | The file or directory is compressed. For a file this means that all of the data in the file is compressed. For a directory this means that compression is the default for newly created files and subdirectories | 0x00000800 | 2048
sgfOffline | The file data is not immediately available. Indicates that the file data has been physically moved to offline storage | 0x00001000 | 4096

Constant | Hexadecimal Value | Decimal Value
Small_16x16 | &H00000010& | 16
Big_32x32 | &H00000020& | 32


SG FileSys Error Codes

SG FileSys |
Error Codes | ©1998 by Stinga
See Also Overview Constants

Error Code | Description
1001 | Failed to create items collection